Repository navigation
Conversation
Agents could not tell an expensive dashboard tile from a cheap one: query_tiles kept only status, hasData and rowCount. Each tile that ran now reports elapsedMs (measured from when it starts, so time waiting in the queue doesn't count, and on failures too, since slow tiles are often the ones that fail), plus ClickHouse's rowsRead and bytesRead when the tile's result carries them. PromQL results get elapsedMs as well: the Prometheus API returns no read counts, so wall time is the only cost signal there. Part of ClickHouse#3649.
🦋 Changeset detectedLatest commit: ab3eea3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@bcanvural is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
| // timeout, folding either into a status:'error' entry so one | ||
| // misbehaving tile never rejects the whole batch. | ||
| const started = Date.now(); | ||
| const elapsed = () => ({ elapsedMs: Date.now() - started }); |
There was a problem hiding this comment.
🟡 P2 — Tiles skipped by the batch deadline still report elapsedMs (≈0), as if they ran
started is captured before withDeadline, and withDeadline (packages/api/src/mcp/utils/timeout.ts:87-90) throws DeadlineExceededError without starting the query once the budget is spent. The catch block then spreads ...elapsed(), so a tile that never ran comes back with elapsedMs: 0. That contradicts the new description ('Each tile that ran reports elapsedMs'), and an agent ranking tiles by cost will read 0 as 'cheap'. Fix: omit elapsedMs when err instanceof DeadlineExceededError and the work never started, or record started inside the thunk passed to withDeadline. Then assert in the existing 'does not issue a query for tiles scheduled after the deadline' test that elapsedMs is absent.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Fixed in ab3eea3: the clock starts inside the work withDeadline runs, so a skipped tile has no elapsedMs. The deadline test now checks that.
| signal: options?.abortSignal, | ||
| }), | ||
| ); | ||
| const started = Date.now(); |
There was a problem hiding this comment.
🟡 P2 — PromQL elapsedMs includes source lookup and backend probing, not just query wall time
started is taken before runPromqlTile, which first runs resolvePromqlTarget (Mongo lookups) and resolvePromqlQueryBackend, which probes the server for its Prometheus HTTP API (packages/api/src/mcp/tools/query/promqlTile.ts:127-150). Only then does it run the queries. The clickstack_promql description calls this "the query's wall time". Fix: either time only the runPromqlQuery calls inside runPromqlTile and return that value, or change the description to say it is the whole tile's wall time, including setup.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Fixed in ab3eea3 by wording: the description now says the call's wall time. It includes the source lookup and backend probe on purpose, since that's part of what the call costs.
PR Review
1 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 0 P3 1 posted as inline comment(s) on the changed lines. Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is an additive observability change: new optional fields ( 🟡 P2 -- recommended
🔵 P3 nitpicks (4)
Reviewers (11): correctness, testing, maintainability, project-standards, kieran-typescript, api-contract, performance, reliability, agent-native, learnings, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Start a tile's clock inside the work withDeadline runs, so a tile that never started reports no time instead of 0, which reads as cheap. Time with performance.now(), and describe the PromQL elapsedMs as the call's wall time: it includes the source lookup and backend probe. Test statistics without bytes_read.
| // tile: the source lookup and backend probe as well as the queries. | ||
| return formatQueryResult({ | ||
| ...result, | ||
| elapsedMs: Math.round(performance.now() - started), |
There was a problem hiding this comment.
🟡 P2 — PromQL and SQL results now report wall time under different keys and units
clickstack_query_tile / clickstack_sql already put ClickHouse's time in result.statistics.elapsed, in seconds (windowedSearch.ts:68-80 builds the same shape). This change puts PromQL time in result.elapsedMs, in milliseconds. An agent comparing tiles from clickstack_query_tile now has to know two field names and two units. Fix: emit PromQL time as statistics: { elapsed: seconds } to match the SQL shape, or add elapsedMs to the builder and SQL branches of runConfigTile as well, so every result carries the same field.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Keeping this as is. statistics is ClickHouse's own block and comes with read counts. A PromQL call has none, so a statistics block with only elapsed would look like ClickHouse output with the counts missing. elapsedMs names its unit.
|
Deep review P2 on Two review rounds are done with no P0/P1 left, so I'll stop on the automated findings here. @brandon-pereira, could you take a look when you have time? |
Summary
Part of #3649 (not all of it; see "Not in this PR").
clickstack_query_tilesreturned onlystatus,hasDataandrowCountper tile, so an agent couldn't tell a tile that read 10 GiB from one that read 4 MB. Now:elapsedMs, its wall time. It's measured from when the tile's query starts, so time spent waiting in the queue (6 tiles at a time) doesn't count. Failed tiles report it too, since the slow tiles are often the ones that fail.rowsReadandbytesRead. These are ClickHouse's own numbers: they're already in each tile's JSON result (statistics), andsummarizeRowsnow keeps them.elapsedMs, inclickstack_promql,clickstack_query_tileand per tile inclickstack_query_tiles. The Prometheus API returns no read counts, so wall time is the only cost signal there. The tool descriptions say so.Not in this PR
X-ClickHouse-Summarywithread_rows: 0, also on ClickHouse master. It never wires query progress to the response, whichHTTPHandlerdoes.system.query_loghas the real numbers under our query id, but only after the log flush. Reported as Prometheus query API: X-ClickHouse-Summary reports read_rows 0 for the PromQL queries it runs ClickHouse#134380.describe_source,event_patterns,emerging_signals). This needs counting inside the ClickHouse client. I'd do it in a follow-up, after feat(mcp): emerging_signals compares both windows in one Drain tree and reports new variants #3753 (which changes the pattern tools) lands.How to reproduce
Starting point:
make dev-int.On
main:clickstack_query_tileson any dashboard returns tiles withoutelapsedMs,rowsReadorbytesRead, andclickstack_promqlreturns noelapsedMs.On this branch:
make dev-int FILE="mcp/__tests__/(dashboards/(queryTiles|promqlQueryTile)|promqlQueryTool)"passes, including the new assertions onelapsedMs,rowsReadandbytesRead.yarn jest src/mcp/__tests__/dashboards/queryTiles(unit) coverssummarizeRowswithstatistics, andelapsedMson a tile that throws.How to test on Vercel preview
N/A — non-UI change.
References
describe_sourcetools return no cost statistics #3649